/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const BaseJsonAdapter = require('../base/BaseJsonAdapter');
const ArticleHrefAdapter = require('../ArticleHrefAdapter');
const iconv = require("iconv-lite");
const vm = require('vm');
const request = require('request-promise');
const logger = require('../../conf/logger');
const querystring = require("querystring")
const cheerio = require('cheerio');
const urlTool = require('url');

/**
 * 北京互金网
 * @type {module.Bjp2p}
 */
module.exports = class SJSWenxunChuangye extends BaseJsonAdapter{

  async reqJson(){
    const body = await this.doRequest();
    let decodeBody = iconv.decode(body, this.encoding).toString();
    let data = JSON.parse(decodeBody);
    if( data[0]['data'] === null || data[0]['data'] === undefined ){
      return JSON.stringify([]);
    }else{
      let contents = []
      let title = ''
      let href = ''
      let startPos = 0
      let endPos = 0
      for (let row of data[2]['data']) {
        title = row['gsdm']+' '+row['gsjc'] +' '+row['hjlb'];
        href = row['ck']
        startPos = href.indexOf('/UpFiles')
        endPos = href.indexOf('\'', startPos)
        href = 'http://reportdocs.static.szse.cn'+href.substr(startPos,endPos-startPos)
        contents.push({
          title:title,
          href:href
        });
      }
      return {data:contents}
    }
  }



}
